import os
import csv

test_label_input_dir = './Final_Test/Images/'
test_label_output_dir = './Final_Test_Label/'

csv_filename = 'GT-final_test.csv'
csv_new_filename = 'label.csv'

label_list = []

num_class = 0

with open(test_label_input_dir + csv_filename) as f:
    reader = csv.reader(f)
    for row in reader:
        if reader.line_num < 2:
            continue
        img_filename, width, height, x1, y1, x2, y2, label = row[0].split(';')
        if len(label) == 1:
            label_for_name = '0' + label
        else:
            label_for_name = label
        img_filename = label_for_name + '_' + img_filename.split('.')[0] + '.jpg'
        label_list.append([img_filename, label])
        
with open(test_label_output_dir + csv_new_filename, 'w') as fw:
    writer = csv.writer(fw)
    for row in label_list:
        writer.writerow(row)

print('Label export finished.')
